﻿using System;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Web;

namespace GlimpseWcf.Client
{
    public class WcfEndpointBehavior : IEndpointBehavior
    {
        private readonly HttpContextBase _context;

        public WcfEndpointBehavior(HttpContextBase context)
        {
            _context = context;
        }

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters){ }
        public void Validate(ServiceEndpoint endpoint) { }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            var inspector = new WcfClientMessageInspector(_context);
            clientRuntime.MessageInspectors.Add(inspector);
            foreach(var operation in clientRuntime.ClientOperations)
                operation.ClientParameterInspectors.Add(inspector);
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            throw new NotImplementedException();
        }
    }
}
